<template>
    <div class="cmt-container">
        <h3>发表评论</h3>
        <hr>
        <textarea placeholder="请输入评论内容（最多120字）" maxlength="120" v-model="msg"></textarea>
        <mt-button type="primary" size="large" @click="postComment">发表评论</mt-button>
        <div class="cmt-list">
            <div class="cmt-item">
                <div class="cmt-title">
                    第1楼&nbsp;&nbsp;用户：匿名用户&nbsp;&nbsp;发表时间：2012-12-12 12:12:12
                </div>
                <div class="cmt-body">
                    锄禾日当午
                </div>
            </div>
            <div class="cmt-item">
                <div class="cmt-title">
                    第1楼&nbsp;&nbsp;用户：匿名用户&nbsp;&nbsp;发表时间：2012-12-12 12:12:12
                </div>
                <div class="cmt-body">
                    锄禾日当午
                </div>
            </div>
            <div class="cmt-item">
                <div class="cmt-title">
                    第1楼&nbsp;&nbsp;用户：匿名用户&nbsp;&nbsp;发表时间：2012-12-12 12:12:12
                </div>
                <div class="cmt-body">
                    锄禾日当午
                </div>
            </div>
        </div>
        <mt-button type="danger" size="large" plain>加载更多</mt-button>
    </div>
</template>
<script>
import {Toast} from 'mint-ui'
export default {
    data(){
        return {
            pageIndex:1,
            comments:{},
            msg:''
        }
    },
    created(){
        this.getComments()
    },
    methods: {
        getComments(){
            this.$http.get('users/'+this.id+"?pageindex="+this.pageIndex).then(result=>{
                if(result.status===200){
                    this.comments=result.body
                }else{
                    Toast('获取新闻失败')
                }
            })
        },
        postComment(){
            if(this.msg.trim().length===0){
                return Toast('评论内容不能为空')
            }
            this.$http.post('posts',{userId:1,title:'foo',body:this.msg})
            .then(function(result){
                if(result.status===201){
                    Toast('评论成功')
                    this.msg=''
                }else{
                    Toast('评论失败')
                }
            })
        }
    },
    props:["id"]
}
</script>
<style>
.cmt-container h3{
    font-size: 18px;
}
.cmt-container textarea{
    font-size: 10px;
    height: 85px;
    margin: 0
}
.cmt-list{
    margin: 5px 0
}
.cmt-list .cmt-item{
    font-size: 13px;
}
.cmt-list .cmt-item .cmt-title{
    background-color: #ccc;
    line-height: 30px
}
.cmt-list .cmt-item .cmt-body{
    line-height: 35px;
    text-indent:2em;
}
</style>
